<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

<script>

    function Cat(name, age) {
        this.name = name
        this.age = age
        Cat.prototype.say = function () { console.log(this.name, this.age) }
        Cat.prototype.want = function () { console.log(this.name + '想抓Jerry!') }
        Cat.prototype.wantsay = function () { console.log(this.name + '说他想抓Jerry!' + 'Cat') }
    }

    function BlueCat(name, age, hobby) {
        Cat.call(this, name, age)// 调用父类构造函数, 强制将函数中的this指向子类  在执行过程创建的实例化对象
        this.hobby = hobby
        BlueCat.prototype.sayy = function () { console.log('我是BlueCat的sayy') }
    }

    // 用父类的实例化对象覆盖子类的原型对象
    // Cat的原型链: Cat -> Cat.prototype -> Object.prototype -> null
    // BlueCat的原型链: BlueCat -> BlueCat.prototype(Cat) -> Cat.prototype -> Object.prototype -> null
    //(1)把BlueCat.prototype指向构造函数 new Cat
    // BlueCat.prototype = new Cat()
    // BlueCat.prototype.constructor = BlueCat
    //(2)借用Object.create
    BlueCat.prototype = Object.create(Cat.prototype)
    // BlueCat.prototype.constructor = BlueCat
    BlueCat.prototype.wantsay = function () { console.log(this.name + '说他想抓Jerry!' + 'BlueCat') }

    var blueCat = new BlueCat('Tom', '6', 'CATCH MOUSE')

    console.log(blueCat)
    blueCat.wantsay()
</script>

</html>